package com.example.home.mvvm.viewmodel

import androidx.lifecycle.MutableLiveData
import com.example.home.api.HomeApiManager
import com.example.home.mvvm.bean.HomeBean
import com.gsafety.library.Base.BaseViewModel
import com.gsafety.libraryktx.bean.LoadState
import com.gsafety.libraryktx.expand.commonEq
import com.gsafety.libraryktx.expand.enqueue
import com.gsafety.libraryktx.manager.UserManager
import com.gsafety.libraryktx.net.api.request.RequestParamsManager


/**首页
 * @author : lj
 * @date : 2020/9/23 16:53
 */
class HomeViewModel: BaseViewModel(){
    var loadState = MutableLiveData<LoadState>()
    var data = MutableLiveData<HomeBean>()
    fun requesthome(){
        loadState.value = LoadState.Loading()
        var user=UserManager.getInstance().getUser()
        enqueue(HomeApiManager.apiService.home(RequestParamsManager.home(user!!.orgType,user.userId!!)),onSuccess={ result ->
            data.value=result
            loadState.value = LoadState.Success()
        },onFail={ error->
            loadState.value = LoadState.Fail(error?: "")

        })
    }


    fun logout(){
        commonEq(HomeApiManager.loginapiService.loginOut(UserManager.getInstance().getToken()),onSuccess={ result ->
        },onFail={ error->

        })
    }


}